1076A - Minimizing the String - CodeForces Solution


greedy strings *1200

Please click on ads to support us..

Python Code:

n = int(input())
s = input()
i = 0
while i!= n-1 and s[i] <= s[i+1]:
	i += 1
if i == n-1:
	print(s[:i])
else:
	print(s[:i]+s[i+1:])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
const long long MOD = 1e9 + 7, OO = 1e18;
const double PI = acos(-1);
const int N = 1e5 + 5;

ll t = 1;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i =0; i< n-1;i++){
        if (s[i] > s[i+1]){
            for (int j = 0; j < i;j++){
                cout << s[j];
            }
            for (int j = i+1; j < n;j++){
                cout << s[j];
            }
            return ;
        }
    }
    for (int i =0; i< n-1 ;i++) cout << s[i];
    return;
}

int main() {
    IO
    
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

    


Comments

Submit
0 Comments
More Questions

Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array